package com.one.customer.controller;


import com.one.customer.service.CurstomerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;

@WebServlet("/register.do")
public class CurstomerRegisterController extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String phone = req.getParameter("phone");
        CurstomerService service = new CurstomerService();
        boolean result= service.register(username,password,phone);
        if(result){
            //注册成功后加入首页
            req.getRequestDispatcher("product_list.jsp").forward(req, resp);
        }else {
            //注册失败后回到注册页面
            req.getRequestDispatcher("register.jsp").forward(req, resp);
        }
    }
}
